package com.easidea.tim.flex.remote.finance
{
	import com.easidea.tim.flex.Env;
	import com.easidea.tim.flex.bean.Page;
	import com.easidea.tim.flex.bean.finance.ShouldPayCleanRecord;
	import com.easidea.tim.flex.event.CustomerEvent;
	import com.easidea.tim.flex.remote.BaseDao;
	import com.easidea.tim.flex.util.AppAlert;
	
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	import net.digitalprimates.persistence.hibernate.rpc.HibernateRemoteObject;

	public class ShouldPayCleanRecordDao extends BaseDao
	{
		private var _ShouldPayCleanRecordService:HibernateRemoteObject = new HibernateRemoteObject();
		private static var _instance:ShouldPayCleanRecordDao;
		
		public static function getInstance():ShouldPayCleanRecordDao{
			if( !_instance ){
				_instance = new ShouldPayCleanRecordDao();
				
			}
			return _instance;
		}
		public function ShouldPayCleanRecordDao() {
				_ShouldPayCleanRecordService.channelSet = this.buildChannelSet();
				_ShouldPayCleanRecordService.destination="shouldPayCleanRecordService";	
				_ShouldPayCleanRecordService.concurrency = "last";
				_ShouldPayCleanRecordService.makeObjectsBindable = true;
				_ShouldPayCleanRecordService.showBusyCursor = true;	
		}
		/**
		 * 调用spring方法:根据查询条件分页查询采购支付列表
		 * @param name
		 * @param page
		 * 
		 */		
		public function getShouldPayCleanRecordListByCondition(startDate:Date,endDate:Date,
					orderId:int, supId:int, page:Page):void {	
			
			_ShouldPayCleanRecordService.addEventListener(ResultEvent.RESULT, getShouldPayCleanRecordListByConditionResult);
			_ShouldPayCleanRecordService.addEventListener(FaultEvent.FAULT,_Fault);
			_ShouldPayCleanRecordService.getShouldPayCleanRecordListByCondition(startDate,endDate,orderId,supId, page);
		}

		/**
		 * 根据查询条件分页查询采购支付列表回调函数
		 * @param e
		 * 
		 */			
		private function getShouldPayCleanRecordListByConditionResult(e:ResultEvent):void {		
			_ShouldPayCleanRecordService.removeEventListener(ResultEvent.RESULT, getShouldPayCleanRecordListByConditionResult);
			Env.dispatchEvent(new CustomerEvent("getShouldPayCleanRecordListByConditionSuccess",e.result));				  									 	
		}
		
		/**
		 * 调用spring方法:获取采购订单流水号信息
		 * @param name
		 * @param page
		 * 
		 */		
		public function getAllPurchaseOrderList():void {			
			_ShouldPayCleanRecordService.addEventListener(ResultEvent.RESULT, getAllPurchaseOrderListResult);
			_ShouldPayCleanRecordService.addEventListener(FaultEvent.FAULT, _Fault);
			_ShouldPayCleanRecordService.getAllPurchaseOrderList();
		}
		/**
		 * 获取采购订单流水号信息回调函数
		 * @param e
		 * 
		 */			
		private function getAllPurchaseOrderListResult(e:ResultEvent):void {			 
			_ShouldPayCleanRecordService.removeEventListener(ResultEvent.RESULT, getAllPurchaseOrderListResult);

			 if(e.result != null) {					 				 
				Env.dispatchEvent(new CustomerEvent("getAllPurchaseOrderListSuccess",e.result));				  									 
			 } 
		}	
					
		/**
		 * 调用spring方法:保存采购订单信息
		 * @param name
		 * @param page
		 * 
		 */		
		public function savePay(pay:ShouldPayCleanRecord):void {			
			_ShouldPayCleanRecordService.addEventListener(ResultEvent.RESULT, savePayResult);
			_ShouldPayCleanRecordService.addEventListener(FaultEvent.FAULT, _Fault);
			_ShouldPayCleanRecordService.savePay(pay);
		}
		/**
		 * 保存采购订单信息回调函数
		 * @param e
		 * 
		 */			
		private function savePayResult(e:ResultEvent):void {			 
			_ShouldPayCleanRecordService.removeEventListener(ResultEvent.RESULT, savePayResult);

			 if(e.result != null) {	
			 	if(e.result.toString() == "success") {
			 	 AppAlert.show("保存成功！","信息提示");
			 	 Env.dispatchEvent(new CustomerEvent("savePaySuccess"));	
			 	}				 				 
							  									 
			 } 
		}	
		/**
		 * 调用spring方法:根据查询条件参数分页查询采购支付列表
		 * @param name
		 * @param page
		 * 
		 */		
		public function getShouldPayListByCondition(startDate:Date,endDate:Date,
					supName:String,responser:String ,page:Page):void {	
			
			_ShouldPayCleanRecordService.addEventListener(ResultEvent.RESULT, getShouldPayListByConditionResult);
			_ShouldPayCleanRecordService.addEventListener(FaultEvent.FAULT,_Fault);
			_ShouldPayCleanRecordService.getShouldPayListByCondition(startDate,endDate,supName,responser,page);
		}

		/**
		 * 根据查询条件参数分页查询采购支付列表
		 * @param e
		 * 
		 */			
		private function getShouldPayListByConditionResult(e:ResultEvent):void {		
			_ShouldPayCleanRecordService.removeEventListener(ResultEvent.RESULT, getShouldPayListByConditionResult);
				Env.dispatchEvent(new CustomerEvent("getShouldPayListByConditionSuccess",e.result));				  									 	
		}
			
	}
}